﻿using Microsoft.Extensions.DependencyInjection;
using MingYuanYun.Data.Abstractions;
using System;
using System.Collections.Generic;
using System.Text;

namespace ControlCenter.Operation
{
    internal static class ServiceScopExtensions
    {
        public static T GetRepository<T>(this IServiceScope serviceScope) where T : IRepositoryBase
        {
            var uow = serviceScope.ServiceProvider.GetService<IUnitOfWork>();
            var repository = serviceScope.ServiceProvider.GetService<T>();

            repository.UnitOfWork = uow;

            return repository;
        }

        public static T GetService<T>(this IServiceScope serviceScope)
        {
            return serviceScope.ServiceProvider.GetService<T>();
        }
    }
}
